-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publicize: Move the publicize-connections endpoint to the package #40637
Conversation
This is following on from various discussions we've been having about how to refactor the API endpoints for connections management. This is a variation on the approach in #40607 but repurposes the existing endpoint rather than creating a new backwards compatible one.
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
projects/packages/publicize/src/class-wpcom-rest-api-v2-endpoint-list-publicize-connections.php
Outdated
Show resolved
Hide resolved
projects/packages/publicize/src/class-wpcom-rest-api-v2-endpoint-list-publicize-connections.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have gone back and forth too many times and I don't think we should continue doing that. Let us get this PR in its final shape addressing the comments I added.
I am not sure about your approach about the endpoint initialization on WPCOM, so I will wait for your thoughts on that.
projects/packages/publicize/src/class-wpcom-rest-api-v2-endpoint-list-publicize-connections.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has turned into a bit of a monster, which is a shame. I was hoping we could do this with smaller changes. It's also almost the same as #40607, but I suppose that means we've converged on a solution.
@@ -0,0 +1,431 @@ | |||
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The annoying thing about this change is that this file is now so different from the publicize-connections.php
file it replaces, it's now a new file, rather than the diff showing that it's moved. Overall it is using the same code and method names.
* @return array Connection objects in the same shape as from `get_connections` | ||
*/ | ||
public static function get_connections_data( $run_tests = false ) { | ||
// TODO decide on caching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing we should use a transient like we do in Publicize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caching should ideally happen outside of the controller. We can deal with it later.
$response = Client::wpcom_json_api_request_as_user( sprintf( $path, $site_id ), 'v2', array( 'method' => 'GET' ) ); | ||
|
||
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { | ||
// TODO log error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to work out what's best to do here. I feel like we should return an error. If it's empty like this then everything will still function but will be blank. How do we get an error message to the user? Maybe it's ok for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always return an array here and pass the error in some other way like JITM.
$cmeta = $this->get_connection_meta( $connection ); | ||
$cmeta = $this->get_connection_meta( $connection ); | ||
$username = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since username
field is deprecated in favour of external_handle
, we don't need to update it. We are going to remove it anyway in the future.
It's funny that this PR now has more changes (+473 −307) than #40607 (+459 −31) which it tried not to do 😄 |
), | ||
); | ||
|
||
$test_fields = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please avoid adding these test fields here? We no longer use them. The only field that we need here is the status
field.
We can move this schema back to connection test results endpoint and remove it in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need more than the status field, or we need to make sure the status field can also be must_reauth
for LinkedIn. I think that flow does use some of these other fields too, but it needs some work anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our new connections management uses only the status
field, nothing else.
'test_success' => 'connectionTestPassed', | ||
'test_message' => 'connectionTestMessage', | ||
'error_code' => 'connectionTestErrorCode', | ||
'can_refresh' => 'userCanRefresh', | ||
'refresh_text' => 'refreshText', | ||
'refresh_url' => 'refreshURL', | ||
'connection_id' => 'connectionID', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like these unused fields in this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, we can move them back to the subclass.
* | ||
* @return true|WP_Error | ||
*/ | ||
public function get_items_permission_check() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This callback in the future can be moved to a base class to share between different publicize controllers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was trying to avoid introducing a base class at this stage. I was also trying to make the change a move of the endpoint, but we end up having to make so many other changes to the class, it ends up getting treated as a new file
array( | ||
'connection_id' => $connection_id, | ||
'display_name' => $publicize->get_display_name( $service_name, $connection ), | ||
'external_handle' => $username, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
external_handle
handle is not actually the username. It's a little different. With this PR, I get this, which is incorrect:
You can see the get_external_handle
method I added in #40607
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it seems strange. Why does it only exist for certain networks? https://github.com/Automattic/jetpack/pull/40607/files#diff-540cd16120af78cc4afc265ca572d7dac4674ebd81ec12f9479bf079929dc04aR612-R629?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't have it for Facebook pages for example. We can surely improve on that to ensure that our keyring service has all that information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is taken care of in the accompanying WPCOM PR
Yes, we should fix that. It was introduced from trying to make Phan happy. I'm not sure we should be using the prepare_item_for_response method |
Closing in favour of #40607 |
This is following on from various discussions we've been having about how to refactor the API endpoints for connections management. This is a variation on the approach in #40607 but repurposes the existing endpoint rather than creating a new backwards compatible one.
Fixes #
Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: